package com.struts.action.product;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.spring.service.product.ProductAtrributeService;
import com.struts.form.ProductAtrributeForm;

public class ProductAtrributeAction extends DispatchAction{
	
	private ProductAtrributeService productAtrributeService=null;
	/**
	 * display atrribute leibie
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward findProductAtrribute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
				Long fatherId=0L;
				if(request.getParameter("fatherId")!=null)
					fatherId=Long.parseLong(request.getParameter("fatherId"));
				request.setAttribute("productAtrributeLiebei", productAtrributeService.findProductAtrribute("from ProductAtrribute where fatherId="+fatherId));
				return mapping.findForward("productAtrributeLiebei");
			}
	
	
	/**
	 * save atrribute leibie
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward saveProductAtrribute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		ProductAtrributeForm productatrributeform=(ProductAtrributeForm)form;
		if(productAtrributeService.saveProductAtrribute(productatrributeform))
			return mapping.findForward("success");
		else
			return mapping.findForward("fail");
	}
	
	public ActionForward deleteProductAtrribute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		Long id=Long.parseLong(request.getParameter("id"));
		if(productAtrributeService.deleteProductAtrribute(id))
		{
			return mapping.findForward("success");
		}
		else
		{
			return mapping.findForward("fail");
		}
	}
	
	public ActionForward updateProductAtrribute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		ProductAtrributeForm productatrributeform=(ProductAtrributeForm)form;
		if(productAtrributeService.updateProductAtrribute(productatrributeform))
			return mapping.findForward("success");
		else
			return mapping.findForward("fail");
	}
	
	
	
	public ProductAtrributeService getProductAtrributeService() {
		return productAtrributeService;
	}
	public void setProductAtrributeService(
			ProductAtrributeService productAtrributeService) {
		this.productAtrributeService = productAtrributeService;
	}

}
